const appGlobalData = getApp().globalData;
Component({
  options: {
    addGlobalClass: true,
  },
  /**
   * 组件的属性列表
   */
  properties: {
    gridList: Object
  },

  /**
   * 组件的初始数据
   */
  data: {
    gridCol: 4,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    gridclick(e) {
      let that = this;
      var item = e.currentTarget.dataset;
      if (item.url) {
          if (!appGlobalData.userInfo.mobile) {//授权了，可以获取用户信息了
            
              //重定向到指定的页面
              wx.showModal({
                content: '为了给您提供更好的服务，请登录后使用',
                success (res) {
                  if (res.confirm) {
                    //console.log('用户点击确定')
                    wx.navigateTo({
                      url: "/pages/auth/auth"
                    });
                  } else if (res.cancel) {
                    //console.log('用户点击取消')
                  }
                }
              })
              
          }else{
              if (item.url=='ksjf') {
                if(appGlobalData.customer.jifenTemplateId){
                  wx.requestSubscribeMessage({
                    tmplIds: appGlobalData.customer.jifenTemplateId.split(),
                    success (res) { 
                      console.log(res)
                      var myPluginInterface = requirePlugin('paymentIntegral');
                      myPluginInterface.getLocation(wx.getStorageSync('userInfo').miniOpenid).then(res => {
                        console.log(res)
                      })
                      if(appGlobalData.customer.wxmchid){
                        wx.navigateTo({
                          url: 'plugin://paymentIntegral/index?openid='+wx.getStorageSync('userInfo').miniOpenid+'&mch_id='+appGlobalData.customer.wxmchid,
                        }) 
                      }else{
                        wx.showToast({
                          title:'未配置商户号，请联系管理员',
                          icon:'none'
                        })
                      }
                    },
                    fail(res) { 
                      console.log('123'+res)
                    }
                  })
                }else{
                  var myPluginInterface = requirePlugin('paymentIntegral');
                  myPluginInterface.getLocation(wx.getStorageSync('userInfo').miniOpenid).then(res => {
                    console.log(res)
                  })
                  //查看授权状态
                  // myPluginInterface.getAuthStatus(wx.getStorageSync('token'),'1600628045').then(res => {
                  //   console.log(res)
                  // })
                  //console.log(appGlobalData.customer.wxmchid)
                  //console.log(wx.getStorageSync('userInfo').miniOpenid)
                  if(appGlobalData.customer.wxmchid){
                    wx.navigateTo({
                      url: 'plugin://paymentIntegral/index?openid='+wx.getStorageSync('userInfo').miniOpenid+'&mch_id='+appGlobalData.customer.wxmchid,
                    }) 
                  }else{
                    wx.showToast({
                      title:'未配置商户号，请联系管理员',
                      icon:'none'
                    })
                  }
                }
                
                
              }else{
                if(item.url=='/pages/home/qiandao/index'){
                  if(appGlobalData.customer.jifenTemplateId){
                    wx.requestSubscribeMessage({
                      tmplIds: appGlobalData.customer.jifenTemplateId.split(),
                      success (res) { 
                        wx.navigateTo({
                          url: item.url+'?name='+item.name
                        });
                      },
                      fail(res) { 
                        console.log('123'+res)
                      }
                    })
                  }else{
                    wx.navigateTo({
                      url: item.url+'?name='+item.name
                    });
                  }
                }else{
                  wx.navigateTo({
                    url: item.url+'?name='+item.name
                  });
                }
              }
          }
        
      }else {
        wx.showModal({
          content: "正在建设中，敬请期待！",
          showCancel: false
        })
      }
    },
  }
})
